<template>
	<!-- 添加采购请求 -->
	<view>
		<view class="boxcent">
			<view class="box1">
				<text class="text2 txt">日期:</text>
				<view class="datetime">
					<uni-datetime-picker type="date" v-model="production"></uni-datetime-picker>
				</view>
			</view>
			<view class="br"></view>
			<view class="box1" @click="stopage">
				<text class="text txt">商品名称:</text>
				<input class="text1" type="text" v-model="stoname" placeholder="请选择商品">
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">规格:</text>
				<input class="text1" type="text" disabled="false" v-model="stospe" placeholder="请输入规格">
			</view>
			<view class="br"></view>
			<view class="box1" @click="stopage">
				<text class="text txt">商品编号:</text>
				<input class="text1" type="text" v-model="stoid" placeholder="请选择商品">
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">数量:</text>
				<input class="text1"  @input="get" type="number" v-model="num" placeholder="请输入商品数量">
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">单价:</text>
				<input class="text1" disabled="false" type="number" v-model="purchase_price" placeholder="请输入商品单价">
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">总金额:</text>
				<input class="text1"type="number" disabled="false" v-model="amount" placeholder="商品总金额">
			</view>
			<view class="br"></view>
			<view class="box1" @click="suppage">
				<text class="text txt">供应商:</text>
				<input class="text1" type="text" disabled="false" v-model="supname" placeholder="请选择供应商">
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">资金账户:</text>
				<input class="text1" type="text" disabled="false" v-model="supaccount" placeholder="请选择供应商">
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">经办人:</text>
				<input class="text1" type="text" disabled="false" v-model="whentryname" placeholder="经办人">
			</view>
			<view class="br"></view>
			<view class="box1" @click="warpage">
				<text class="text txt">目标仓库:</text>
				<input class="text1" type="text" disabled="false" v-model="wname" placeholder="请选择仓库名称">
				<image class="img" src="../../../static/paimg/跳转.png"></image>
			</view>
			<view class="br"></view>
			<view class="box1">
				<text class="text txt">详情:</text>
				<input class="text1" type="text" v-model="title" placeholder="空">
			</view>
		</view>
		<view class="btnbox">
			<button @click="inst">保存</button>
		</view>
	</view>
</template>

<script>
	import getDateTime from '../../../until/getdateTime.js'
	export default {
		data() {
			return {
				production:'1900-01-01',stoname:'',stospe:'',stoid:'',num:'',purchase_price:'',
				amount:'',supname:'',supaccount:'',whentryname:'',title:'',supid:'',wname:''
			}
		},
		onLoad() {
			this.getdata();
			this.production = getDateTime.dateTimeStr().substring(0, 10);
		},
		onShow:function(){
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1]; //当前页面
			var name=currPage.name;//商品名称
			var id = currPage.id;//商品编号
			var spe = currPage.spe;//商品规格
			var price = currPage.price;//商品进价
			if(name !==undefined){
				this.stoname = name
				this.stoid = id
				this.stospe = spe
				this.purchase_price =price
			}
			var sname=currPage.sname;//供应商名称
			var saccount = currPage.saccount;//供应商银行账号
			var spid = currPage.sid;//供应商编号
			if(sname !==undefined){
				this.supname = sname
				this.supid = spid
				this.supaccount = saccount
			}
			var warname = currPage.warname;//仓库名称
			var warid = currPage.warid;//仓库编号
			if(warname !==undefined){
				this.wname = warname
				this.wid = warid
			}
		},
		methods: {
			get(){
				this.amount =this.num*this.purchase_price
			},
			async getdata(){
				var account = uni.getStorageSync('account');
				const resname = await this.Request({
					url:'api/employee/emp_getname',
					method:'POST',
					data:{account:account}
				})
				this.whentryname = resname.data[0].empname
			},
			async inst(){
				if(this.num.replace(/\s*/g,"").length == 0 || this.stoname == '' ||
					this.supname == '' || this.supname == ''){
					uni.showToast({
						icon:"error",
						title:'内容不可为空'
					})
				}else {
					const res = await this.Request({
						url:'api/procurerecord/recordadd',
						method:'PUT',
						data:{state:'已下单',wname:this.wname,data:this.production,stoname:this.stoname,stoid:this.stoid,stospe:this.stospe,
							  num:this.num,purchase_price:this.purchase_price,amount:this.amount,
							  supid:this.supid,supname:this.supname,bank_account:this.supaccount,
							  whentryname:this.whentryname,title:this.title}
					})
					if(res.data.affectedRows=1){
						uni.showToast({
							title: '添加成功',
							duration:1000
						})
						setTimeout(() => {
							// this.BackPage(3);
							uni.navigateBack({
								delta:1
							})
						},1000)
					}
				}
			},
			stopage(){
				uni.navigateTo({
					url:'/pages/public/choose/choosegoods'
				})
			},
			suppage(){
				if(this.stoname==''){
					uni.showToast({
						icon:'error',
						title: '请选择商品'
					})
				}else{
					uni.navigateTo({
						url:'/pages/public/choose/choosesup?stoname='+this.stoname+'&typevalue='+"入库"
					})
				}
			},
			warpage(){
				uni.navigateTo({
					url:'/pages/public/choose/choosewar?typevalue=入库'
				})
			},
		}
	}
</script>

<style lang="scss">
	.titlebox{
		width: 100%;
		height: 30px;
		background-color: #efefef;
		display: flex;
		border-bottom: 1px solid #ccc;
		.text{
			margin: 5px 0 5px 5px;
			font-size: 110%;
			font-weight: 600;
			color: #008300;
		}
	}
	.boxcent{
		// margin-top: 10px;
		border-top: 2px solid #ccc;
		border-bottom: 2px solid #ccc;
		border-radius: 10px;
		position: relative;
		.br{
			height: 1px;
			margin-left: 10%;
			background: #a5a5a5;
		}
		.box1{
			display: flex;
			margin-top: 10px;
			margin-bottom: 10px;
			
			width: 100%;
			.txt{
				position: absolute;
				font-weight: 600;
				font-size: 110%;
			}
			.radio{
				position: relative;
				margin-left: 150px;
			}
			.radio1{
				position: relative;
				margin-left: 93px;
			}
			.img{
				position: absolute;
				height: 20px;
				width: 20px;
				margin-left: 355px;
			}
			.datetime{
				margin-left: 150px;
				width: 180px;
			}
			.text{
				margin-left: 10%;
			}
			.text1{
				margin-left: 170px;
			}
			.text2{
				margin-left: 10%;
				margin-top: 10px;
			}
			.text3{
				margin-left: 170px;
			}
		}
	}
	.btnbox{
		margin-top: 15px;
		margin-bottom: 60px;
		button{
			width: 50%;
			background-color: #ff5500;
			color: #ffffff;
		}
	}
</style>

